```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nginx动态路由技术指南</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 700;
            color: #2d3748;
        }
        .hero {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background: #2d3748;
            border-left: 4px solid #667eea;
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
        }
        .mermaid-tooltip {
            background: #fff;
            border: 1px solid #e2e8f0;
            border-radius: 4px;
            padding: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4">Nginx动态路由技术</h1>
                    <p class="text-xl text-blue-100 mb-6">基于请求内容智能分发流量的高级配置指南</p>
                    <div class="flex items-center">
                        <span class="bg-white text-blue-700 px-3 py-1 rounded-full text-sm font-semibold mr-3">高级技巧</span>
                        <span class="bg-blue-900 bg-opacity-50 text-blue-100 px-3 py-1 rounded-full text-sm font-semibold">服务器配置</span>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="relative">
                        <div class="w-64 h-64 bg-blue-400 rounded-full filter blur-xl opacity-20 absolute -top-10 -left-10"></div>
                        <div class="w-64 h-64 bg-purple-400 rounded-full filter blur-xl opacity-20 absolute -bottom-10 -right-10"></div>
                        <div class="relative z-10">
                            <div class="bg-white bg-opacity-10 backdrop-filter backdrop-blur-lg rounded-2xl p-6 border border-white border-opacity-20">
                                <div class="flex items-center mb-4">
                                    <div class="w-3 h-3 bg-red-400 rounded-full mr-2"></div>
                                    <div class="w-3 h-3 bg-yellow-400 rounded-full mr-2"></div>
                                    <div class="w-3 h-3 bg-green-400 rounded-full"></div>
                                </div>
                                <pre class="text-xs text-blue-100 font-mono overflow-x-auto"><code>location / {
    # 动态路由逻辑
    content_by_lua_block {
        if ngx.var.http_x_header then
            ngx.exec("@backend_1")
        else
            ngx.exec("@default")
        end
    }
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl py-12 px-4 md:px-0">
        <!-- Introduction -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-8 h-8 bg-blue-500 rounded-full flex items-center justify-center mr-3">
                    <i class="fas fa-info-circle text-white text-sm"></i>
                </div>
                <h2 class="text-2xl font-bold">技术概览</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md p-6">
                <p class="text-gray-700 mb-4">在Nginx中实现基于请求内容的动态路由是一种高级配置技术，它允许根据请求的不同部分（如请求头、请求路径、查询参数等）将请求智能地转发到不同的后端服务器。</p>
                <p class="text-gray-700">这种技术广泛应用于微服务架构、AB测试、多租户系统等场景，能够显著提高系统的灵活性和可维护性。</p>
            </div>
        </section>

        <!-- Visualization -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-8 h-8 bg-green-500 rounded-full flex items-center justify-center mr-3">
                    <i class="fas fa-project-diagram text-white text-sm"></i>
                </div>
                <h2 class="text-2xl font-bold">动态路由工作流程</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md p-6">
                <div class="mermaid">
                    graph TD
                        A[客户端请求] --> B{Nginx网关}
                        B -->|请求头匹配| C[后端服务1]
                        B -->|路径匹配| D[后端服务2]
                        B -->|参数匹配| E[后端服务3]
                        B -->|默认路由| F[默认服务]
                        style A fill:#e2e8f0,stroke:#94a3b8
                        style B fill:#c7d2fe,stroke:#818cf8
                        style C fill:#bae6fd,stroke:#38bdf8
                        style D fill:#a7f3d0,stroke:#34d399
                        style E fill:#fbcfe8,stroke:#f472b6
                        style F fill:#fecaca,stroke:#f87171
                </div>
            </div>
        </section>

        <!-- Method 1 -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-8 h-8 bg-purple-500 rounded-full flex items-center justify-center mr-3">
                    <span class="text-white font-bold">1</span>
                </div>
                <h2 class="text-2xl font-bold">基于请求头的动态路由</h2>
            </div>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="card bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-heading text-purple-600"></i>
                            </div>
                            <h3 class="text-lg font-semibold">核心原理</h3>
                        </div>
                        <p class="text-gray-700 mb-4">通过 <code class="bg-gray-100 px-1 py-0.5 rounded">map</code> 指令将请求头的值映射到特定的变量，然后基于这些变量进行路由决策。</p>
                        <div class="bg-gray-100 p-3 rounded-lg">
                            <ul class="list-disc pl-5 text-gray-700">
                                <li class="mb-2">适用于需要根据客户端类型、API版本等进行路由的场景</li>
                                <li class="mb-2">常用于灰度发布、AB测试等</li>
                                <li>性能开销较低，适合高频请求</li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="code-block rounded-xl overflow-hidden">
                    <div class="px-4 py-2 bg-gray-800 text-gray-300 flex items-center">
                        <div class="w-3 h-3 bg-red-500 rounded-full mr-2"></div>
                        <div class="w-3 h-3 bg-yellow-500 rounded-full mr-2"></div>
                        <div class="w-3 h-3 bg-green-500 rounded-full mr-3"></div>
                        <span class="text-sm">nginx.conf</span>
                    </div>
                    <pre class="p-4 text-gray-300 overflow-x-auto"><code>http {
    # 映射请求头值到变量
    map $http_x_custom_header $backend {
        default         backend_default;
        "value1"        backend_1;
        "value2"        backend_2;
    }

    upstream backend_1 {
        server backend1.demo.com;
    }

    upstream backend_2 {
        server backend2.demo.com;
    }

    upstream backend_default {
        server default.demo.com;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://$backend;
        }
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Method 2 -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-8 h-8 bg-blue-500 rounded-full flex items-center justify-center mr-3">
                    <span class="text-white font-bold">2</span>
                </div>
                <h2 class="text-2xl font-bold">基于请求路径的动态路由</h2>
            </div>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="card bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-route text-blue-600"></i>
                            </div>
                            <h3 class="text-lg font-semibold">核心原理</h3>
                        </div>
                        <p class="text-gray-700 mb-4">使用 <code class="bg-gray-100 px-1 py-0.5 rounded">location</code> 指令通过匹配请求路径来进行路由，是最常见的路由方式。</p>
                        <div class="bg-gray-100 p-3 rounded-lg">
                            <ul class="list-disc pl-5 text-gray-700">
                                <li class="mb-2">适用于微服务架构，不同路径对应不同服务</li>
                                <li class="mb-2">支持前缀匹配、精确匹配、正则匹配等多种方式</li>
                                <li>配置简单直观，易于维护</li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="code-block rounded-xl overflow-hidden">
                    <div class="px-4 py-2 bg-gray-800 text-gray-300 flex items-center">
                        <div class="w-3 h-3 bg-red-500 rounded-full mr-2"></div>
                        <div class="w-3 h-3 bg-yellow-500 rounded-full mr-2"></div>
                        <div class="w-3 h-3 bg-green-500 rounded-full mr-3"></div>
                        <span class="text-sm">nginx.conf</span>
                    </div>
                    <pre class="p-4 text-gray-300 overflow-x-auto"><code>server {
    listen 80;

    # 根据请求路径路由到不同的后端
    location /service1/ {
        proxy_pass http://backend_service1;
    }

    location /service2/ {
        proxy_pass http://backend_service2;
    }

    # 默认处理
    location / {
        proxy_pass http://default_backend;
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Method 3 -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-8 h-8 bg-green-500 rounded-full flex items-center justify-center mr-3">
                    <span class="text-white font-bold">3</span>
                </div>
                <h2 class="text-2xl font-bold">基于查询参数的动态路由</h2>
            </div>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="card bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 bg-green-100 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-search text-green-600"></i>
                            </div>
                            <h3 class="text-lg font-semibold">核心原理</h3>
                        </div>
                        <p class="text-gray-700 mb-4">通过 <code class="bg-gray-100 px-1 py-0.5 rounded">map</code> 指令结合查询参数的值来实现动态路由，适用于需要根据URL参数决定后端服务的场景。</p>
                        <div class="bg-gray-100 p-3 rounded-lg">
                            <ul class="list-disc pl-5 text-gray-700">
                                <li class="mb-2">适用于多租户系统、API版本控制等</li>
                                <li class="mb-2">可以实现无需修改路径的动态路由</li>
                                <li>需要注意URL参数的安全性</li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="code-block rounded-xl overflow-hidden">
                    <div class="px-4 py-2 bg-gray-800 text-gray-300 flex items-center">
                        <div class="w-3 h-3 bg-red-500 rounded-full mr-2"></div>
                        <div class="w-3 h-3 bg-yellow-500 rounded-full mr-2"></div>
                        <div class="w-3 h-3 bg-green-500 rounded-full mr-3"></div>
                        <span class="text-sm">nginx.conf</span>
                    </div>
                    <pre class="p-4 text-gray-300 overflow-x-auto"><code>http {
    # 提取查询参数并映射到变量
    map $arg_param $backend {
        default         backend_default;
        "value1"        backend_1;
        "value2"        backend_2;
    }

    upstream backend_1 {
        server backend1.demo.com;
    }

    upstream backend_2 {
        server backend2.demo.com;
    }

    upstream backend_default {
        server default.demo.com;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://$backend;
        }
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Method 4 -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-8 h-8 bg-yellow-500 rounded-full flex items-center justify-center mr-3">
                    <span class="text-white font-bold">4</span>
                </div>
                <h2 class="text-2xl font-bold">使用Nginx的Lua模块进行复杂路由</h2>
            </div>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="card bg-white rounded-xl shadow-md overflow-hidden">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 bg-yellow-100 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-code text-yellow-600"></i>
                            </div>
                            <h3 class="text-lg font-semibold">核心原理</h3>
                        </div>
                        <p class="text-gray-700 mb-4">对于复杂的动态路由需求，可以使用 <code class="bg-gray-100 px-1 py-0.5 rounded">ngx_lua</code> 模块编写Lua脚本来处理请求内容并进行路由。</p>
                        <div class="bg-gray-100 p-3 rounded-lg">
                            <ul class="list-disc pl-5 text-gray-700">
                                <li class="mb-2">适用于需要复杂业务逻辑的路由决策</li>
                                <li class="mb-2">可以实现请求内容解析、数据库查询等高级功能</li>
                                <li>性能开销较大，适用于低频复杂路由</li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="code-block rounded-xl overflow-hidden">
                    <div class="px-4 py-2 bg-gray-800 text-gray-300 flex items-center">
                        <div class="w-3 h-3 bg-red-500 rounded-full mr-2"></div>
                        <div class="w-3 h-3 bg-yellow-500 rounded-full mr-2"></div>
                        <div class="w-3 h-3 bg-green-500 rounded-full mr-3"></div>
                        <span class="text-sm">nginx.conf</span>
                    </div>
                    <pre class="p-4 text-gray-300 overflow-x-auto"><code>http {
    server {
        listen 80;

        location / {
            # 使用Lua脚本处理请求
            content_by_lua_block {
                local header_value = ngx.var.http_x_custom_header
                if header_value == "value1" then
                    ngx.exec("@backend_1")
                elseif header_value == "value2" then
                    ngx.exec("@backend_2")
                else
                    ngx.exec("@backend_default")
                end
            }
        }

        location @backend_1 {
            proxy_pass http://backend_service1;
        }

        location @backend_2 {
            proxy_pass http://backend_service2;
        }

        location @backend_default {
            proxy_pass http://default_backend;
        }
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Comparison Table -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-8 h-8 bg-red-500 rounded-full flex items-center justify-center mr-3">
                    <i class="fas fa-balance-scale text-white text-sm"></i>
                </div>
                <h2 class="text-2xl font-bold">路由方法对比</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md overflow-hidden">
                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">方法</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">适用场景</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">复杂度</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">性能</th>
                                <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">灵活性</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            <tr class="hover:bg-gray-50">
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">请求头路由</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">灰度发布、AB测试</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">中</td>
                            </tr>
                            <tr class="hover:bg-gray-50">
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">路径路由</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">微服务架构</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">中</td>
                            </tr>
                            <tr class="hover:bg-gray-50">
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">参数路由</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">多租户系统</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">中</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">中</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                            </tr>
                            <tr class="hover:bg-gray-50">
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">Lua脚本路由</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">复杂业务逻辑</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">高</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">低</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">极高</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </section>

        <!-- Best Practices -->
        <section class="mb-16">
            <div class="flex items-center mb-6">
                <div class="w-8 h-8 bg-indigo-500 rounded-full flex items-center justify-center mr-3">
                    <i class="fas fa-star text-white text-sm"></i>
                </div>
                <h2 class="text-2xl font-bold">最佳实践建议</h2>
            </div>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="card bg-white rounded-xl shadow-md overflow-hidden h-full">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 bg-indigo-100 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-tachometer-alt text-indigo-600"></i>
                            </div>
                            <h3 class="text-lg font-semibold">性能优化</h3>
                        </div>
                        <ul class="list-disc pl-5 text-gray-700 space-y-2">
                            <li>优先使用简单的路径或请求头路由</li>
                            <li>避免在Lua脚本中执行耗时操作</li>
                            <li>合理设置Nginx缓存</li>
                        </ul>
                    </div>
                </div>
                <div class="card bg-white rounded-xl shadow-md overflow-hidden h-full">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 bg-green-100 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-shield-alt text-green-600"></i>
                            </div>
                            <h3 class="text-lg font-semibold">安全保障</h3>
                        </div>
                        <ul class="list-disc pl-5 text-gray-700 space-y-2">
                            <li>验证所有输入参数</li>
                            <li>限制Lua脚本的执行权限</li>
                            <li>实施严格的访问控制策略</li>
                        </ul>
                    </div>
                </div>
                <div class="card bg-white rounded-xl shadow-md overflow-hidden h-full">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center mr-3">
                                <i class="fas fa-cogs text-blue-600"></i>
                            </div>
                            <h3 class="text-lg font-semibold">维护建议</h3>
                        </div>
                        <ul class="list-disc pl-5 text-gray-700 space-y-2">
                            <li>保持配置文件的模块化和可读性</li>
                            <li>为复杂路由添加详细注释</li>
                            <li>实施配置版本控制</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto max-w-5xl px-4 md:px-0">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-lg font-semibold text-white">技术小馆</h3>
                    <p class="text-sm">专业的服务器技术分享平台</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-blue-400 hover:text-blue-300 transition-colors duration-200" target="_blank">
                        <i class="fas fa-external-link-alt mr-2"></i>访问技术小馆
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Initialize Mermaid
            mermaid.initialize({
                startOnLoad: true,
                theme: 'default',
                flowchart: {
                    useMaxWidth: false,
                    htmlLabels: true
                }
            });

            // Smooth scroll for anchor links
            document.querySelectorAll('a[href^="#"]').forEach(anchor => {
                anchor.addEventListener('click', function (e) {
                    e.preventDefault();
                    document.querySelector(this.getAttribute('href')).scrollIntoView({
                        behavior: 'smooth'
                    });
                });
            });

            // Add hover effect to table rows
            const tableRows = document.querySelectorAll('tr');
            tableRows.forEach(row => {
                row.addEventListener('mouseenter', () => {
                    row.classList.add('bg-gray-50');
                });
                row.addEventListener('mouseleave', () => {
                    row.classList.remove('bg-gray-50');
                });
            });
        });
    </script>
</body>
</html>
```